package com.smbms.controller;

import com.smbms.pojo.Bill;
import com.smbms.service.BillService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bill")
public class BillController {
    @Resource
    private BillService billService;

    @ResponseBody
    @RequestMapping("/getBillList/{pageNow}/{pageSize}")
    public Object getBillList(@PathVariable Integer pageNow,@PathVariable Integer pageSize, String productName,
                              Integer providerId, Integer isPayment){
        Map<String,Object> result=new HashMap<>();
        //查询订单总数
        int count=billService.getBillCount(productName,providerId,isPayment);
        //计算总页数
        int pageTotal=(int)Math.ceil((double) count/pageSize);
        //查询用户列表
        //封装参数
        int start=(pageNow-1)*pageSize;
        Map<String,Object> data=new HashMap<>();
        data.put("start",start);
        data.put("pageSize",pageSize);
        data.put("productName",productName);
        data.put("providerId",providerId);
        data.put("isPayment",isPayment);
        List<Bill> billList=billService.getBillList(data);
        //封装用户列表数据
        Map<String,Object> map=new HashMap<>();
        map.put("flag",true);
        map.put("msg","订单列表条件查询success");
        map.put("data",billList);
        map.put("count",count);
        map.put("pageTotal",pageTotal);
        map.put("pageNow",pageNow);

        //最终数据
        result.put("flag",true);
        result.put("msg","订单列表分页条件查询success");
        result.put("data",map);

        return result;
    }
}
